package com.junyidao.game.controller;

import com.junyidao.game.core.LoginInfo;
import com.junyidao.game.core.annotation.Action;
import com.junyidao.game.pojo.SysUser;
import com.junyidao.game.service.AccountDetailService;
import com.junyidao.game.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * Created by zzh on 2016/10/7.
 * 文件描述 ：充值查询
 */
@Controller
@RequestMapping("/accountChargeReport")
public class AccountChargeReportController extends BaseController {

    @Autowired
    private UserService userService;

    @Autowired
    private AccountDetailService accountDetailService;

    @RequestMapping
    @Action(desc = "充值查询")
    public ModelAndView list() {
        ModelAndView result = new ModelAndView("report/account_charge_list");
        SysUser user = LoginInfo.getUser();
        List<SysUser> userList = userService.getSubUser(user);
        result.addObject("userList", userList);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/list")
    @Action(desc = "充值列表", sysPriv = false)
    public Map<String, Object> listData(String beginTime, String endTime, String uid, Integer page, Integer rows) {
        Integer puid = LoginInfo.getUser().getUid();
        Integer id = null;
        if (!StringUtils.isEmpty(uid)) {
            id = Integer.valueOf(uid);
            puid = null;
        }
        Map<String, Object> map = accountDetailService.getAccountChargeDay(beginTime, endTime, id, puid, page, rows);
        return resultSucess(map);
    }

    @RequestMapping(value = "toDetail")
    @Action(desc = "充值查询")
    public ModelAndView toDetail(String uid, String day) {
        ModelAndView result = new ModelAndView("report/account_charge_detail");
        SysUser user = LoginInfo.getUser();
        List<SysUser> userList = userService.getSubUser(user);
        result.addObject("userList", userList);
        result.addObject("uid", StringUtils.isEmpty(uid) ? -1 : Integer.valueOf(uid));
        result.addObject("day", day);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/listDetail")
    @Action(desc = "充值明细", sysPriv = false)
    public Map<String, Object> listDetail(String beginTime, String endTime, String uid, Integer page, Integer rows) {
        Integer puid = LoginInfo.getUser().getUid();
        Integer id = null;
        if (!StringUtils.isEmpty(uid)) {
            id = Integer.valueOf(uid);
            puid = null;
        }
        Map<String, Object> map = accountDetailService.getAccountChargeDetail(beginTime, endTime, id, puid, page, rows);
        return resultSucess(map);
    }

}
